package com.sure.yyr.security.login.impl;

import com.sure.yyr.security.login.LoginDto;
import com.sure.yyr.security.login.LoginService;
import com.sure.yyr.security.login.dao.LoginDao;
import com.sure.yyr.security.login.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service @Transactional
public class LoginServiceImpl implements LoginService {

    @Resource
    private LoginDao loginDao;

    @Override
    public boolean checkLogin(LoginDto dto) {
        int cnt = loginDao.findCountByUserIdAndPassword(dto);
        return cnt > 0;
    }

    @Override
    public void registUser(LoginDto dto) {
        User user = getUserById(dto.getU_id());
        if(user != null){
            throw new RuntimeException("已存在相同账号的用户！");
        }
        dto.setU_status("00");
        loginDao.insertUser(dto);
    }

    @Override
    public User getUserById(String u_id) {
        User user = loginDao.findUserById(u_id);
        return user;
    }
}
